<?php
    include_once("../action/checkAuthenticationAction.php");
	include_once("../service/receiptService.php");
	include_once("../service/productService.php");
    include_once("../service/userService.php");
	
	if(isset($_GET["id"])){
	   $receiptInfo = mysql_fetch_array(findReceiptBy($_GET["id"]));
       $userInfo = mysql_fetch_array(findUserById($receiptInfo["USER_ID"]));
       $now = new DateTime();
       $subtotal = 0;
	} else{
		echo "<script>window.location.href = 'receipt.php';</script>";	
	}
?>
<html>

<head>
<meta http-equiv=Content-Type content="text/html; charset=utf-8">
<meta name=Generator content="Microsoft Word 14 (filtered)">
<style>
<style>
<!--
 /* Font Definitions */
 @font-face
	{font-family:Calibri;
	panose-1:2 15 5 2 2 2 4 3 2 4;}
 /* Style Definitions */
 p.MsoNormal, li.MsoNormal, div.MsoNormal
	{margin-top:0in;
	margin-right:0in;
	margin-bottom:10.0pt;
	margin-left:0in;
	line-height:115%;
	font-size:11.0pt;
	font-family:"Calibri","sans-serif";}
p.MsoHeader, li.MsoHeader, div.MsoHeader
	{mso-style-link:"Header Char";
	margin:0in;
	margin-bottom:.0001pt;
	font-size:11.0pt;
	font-family:"Calibri","sans-serif";}
p.MsoFooter, li.MsoFooter, div.MsoFooter
	{mso-style-link:"Footer Char";
	margin:0in;
	margin-bottom:.0001pt;
	font-size:11.0pt;
	font-family:"Calibri","sans-serif";}
a:link, span.MsoHyperlink
	{color:blue;
	text-decoration:none;}
a:visited, span.MsoHyperlinkFollowed
	{color:purple;
	text-decoration:none;}
span.HeaderChar
	{mso-style-name:"Header Char";
	mso-style-link:Header;}
span.FooterChar
	{mso-style-name:"Footer Char";
	mso-style-link:Footer;}
.MsoChpDefault
	{font-family:"Calibri","sans-serif";}
.MsoPapDefault
	{margin-bottom:10.0pt;
	line-height:115%;}
 /* Page Definitions */
@page WordSection1
	{size:595.35pt 841.95pt;
	margin:.75in .75in .75in .75in;}
div.WordSection1
	{page:WordSection1; position:relative;}
legend { color: #F00; }
-->
table#cart td { vertical-align: middle !important; }
img { margin-top: 3px; }
</style>
<title>In hóa đơn - <?php echo $receiptInfo["REC_CODE"];?></title>
</head>

<body lang=EN-US link=blue vlink=purple>

<div class=WordSection1>
<p class=MsoNormal style='margin-bottom:0in;margin-bottom:.0001pt;line-height:
normal'><b><span style='font-size:12.0pt;font-family:"Arial","sans-serif"'>CÔNG
TY TNHH MAY TÚI XÁCH MINH TIẾN</span></b></p>

<p class=MsoNormal style='margin-bottom:0in;margin-bottom:2px;line-height:
normal'><span style='font-size:12.0pt;font-family:"Arial","sans-serif"'>155 Dạ
Nam, P.3, Q.8, TP. Hồ Chí Minh<b style="float:right;">ORDER #<?php echo $receiptInfo["REC_ID"];?>- <?php echo $receiptInfo["REC_CODE"];?></b></span></p>

<p class=MsoNormal style='margin-bottom:0in;margin-bottom:.0001pt;line-height:
normal'><b><span style='font-size:12.0pt;font-family:"Arial","sans-serif"'>Điện
thoại:</span></b><span style='font-size:12.0pt;font-family:"Arial","sans-serif"'>
08.39 820 196 - 08.39 820 186<b style="float:right;"><?php echo $now->format("G:i");?>, <?php echo $now->format("d/m/Y");?></b></span></p>

<p class=MsoNormal style='margin-bottom:0in;margin-bottom:.0001pt;line-height:
normal'><b><span style='font-size:12.0pt;font-family:"Arial","sans-serif"'>Email:</span></b><span
style='font-size:12.0pt;font-family:"Arial","sans-serif"'> </span><a
href="mailto:info@miti.vn"><span style='font-size:12.0pt;font-family:"Arial","sans-serif";
color:red;text-decoration:none'>info@miti.vn</span></a></p>

<p class=MsoNormal style='margin-bottom:0in;margin-bottom:.0001pt;line-height:
normal'><span style='font-size:12.0pt;font-family:"Arial","sans-serif"'>&nbsp;</span></p>

<p class=MsoNormal style='margin-bottom:0in;margin-bottom:.0001pt;line-height:
normal'><span style='font-size:12.0pt;font-family:"Arial","sans-serif"'>&nbsp;</span></p>
	
    <fieldset>
    	<legend>THÔNG TIN ĐƠN HÀNG</legend>
        <table class=MsoTableGrid border=0 cellspacing=0 cellpadding=0 style='border-collapse:collapse;border:none'>
            <tr>
                <td width=332 valign=top style='width:249.05pt;padding:0in 5.4pt 0in 5.4pt'>
                    <p class=MsoNormal style='margin-bottom:0in;margin-bottom:.0001pt;line-height:normal'><b>
                        <span style='font-size:12.0pt;font-family:"Arial","sans-serif"'>Địa chỉ thanh toán:</span></b>
                      </p>
                    <p class=MsoNormal style='margin-bottom:0in;margin-bottom:.0001pt;line-height:normal'>
                        <span style='font-size:12.0pt;font-family:"Arial","sans-serif"'>Họ tên: <strong><?php echo $userInfo["USER_FULLNAME"];?></strong></span>
                    </p>
                    <p class=MsoNormal style='margin-bottom:0in;margin-bottom:.0001pt;line-height: normal'>
                        <span style='font-size:12.0pt;font-family:"Arial","sans-serif"'>Địa chỉ: <?php echo $receiptInfo["REC_PAYINGADDRESS"];?></span>
                    </p>
                    <p class=MsoNormal style='margin-bottom:0in;margin-bottom:.0001pt;line-height: normal'>
                        <span style='font-size:12.0pt;font-family:"Arial","sans-serif"'>Điện thoại: <?php echo $userInfo["USER_PHONENUMBER"];?></span>
                    </p>
                    <p class=MsoNormal style='margin-bottom:0in;margin-bottom:.0001pt;line-height:normal'>
                        <span style='font-size:12.0pt;font-family:"Arial","sans-serif"'>E-mail: <?php echo $userInfo["USER_EMAIL"];?></span>
                    </p>
                </td>
                <td width=332 valign=top style='width:249.1pt;padding:0in 5.4pt 0in 5.4pt'>
                    <p class=MsoNormal style='margin-bottom:0in;margin-bottom:.0001pt;line-height:normal'>
                        <b><span style='font-size:12.0pt;font-family:"Arial","sans-serif"'>Địa chỉ giao hàng:</span></b>
                    </p>
                    <p class=MsoNormal style='margin-bottom:0in;margin-bottom:.0001pt;line-height:normal'>
                        <span style='font-size:12.0pt;font-family:"Arial","sans-serif"'>Họ tên: <strong><?php echo $userInfo["USER_FULLNAME"];?></strong></span>
                    </p>
                    <p class=MsoNormal style='margin-bottom:0in;margin-bottom:.0001pt;line-height:normal'>
                        <span style='font-size:12.0pt;font-family:"Arial","sans-serif"'>Địa chỉ: <?php echo $receiptInfo["REC_DELIVERYINGADDRESS"];?></span>
                    </p>
                    <p class=MsoNormal style='margin-bottom:0in;margin-bottom:.0001pt;line-height:normal'>
                        <span style='font-size:12.0pt;font-family:"Arial","sans-serif"'>Điện thoại: <?php echo $receiptInfo["REC_PHONENUMBER"];?></span>
                    </p>
                </td>
            </tr>
            <tr>
                <td width=332 valign=top style='width:249.05pt;padding:0in 5.4pt 0in 5.4pt'>
                    <p class=MsoNormal style='margin-bottom:0in;margin-bottom:.0001pt;line-height: normal'>
                        <span style='font-size:12.0pt;font-family:"Arial","sans-serif"'>&nbsp;</span>
                    </p>
                    <p class=MsoNormal style='margin-bottom:0in;margin-bottom:.0001pt;line-height:normal'>
                        <b><span style='font-size:12.0pt;font-family:"Arial","sans-serif"'>Phương thức thanh toán:</span></b>
                    </p>
                    <p class=MsoNormal style='margin-bottom:0in;margin-bottom:.0001pt;line-height: normal'>
                        <span style='font-size:12.0pt;font-family:"Arial","sans-serif"'>Trả trực tiếp khi nhận hàng</span>
                    </p>
                </td>
                    <td width=332 valign=top style='width:249.1pt;padding:0in 5.4pt 0in 5.4pt'>
                        <p class=MsoNormal style='margin-bottom:0in;margin-bottom:.0001pt;line-height: normal'><span style='font-size:12.0pt;font-family:"Arial","sans-serif"'>&nbsp;</span>
                    </p>
                    <p class=MsoNormal style='margin-bottom:0in;margin-bottom:.0001pt;line-height:normal'><b>
                        <span style='font-size:12.0pt;font-family:"Arial","sans-serif"'>Phương thức giao hàng:</span></b>
                    </p>
                    <p class=MsoNormal style='margin-bottom:0in;margin-bottom:.0001pt;line-height:normal'>
                        <span style='font-size:12.0pt;font-family:"Arial","sans-serif"'>Chính
                            sách giao hàng của công ty. Cước phí vận chuyển sẽ được thông báo trực tiếp đến khách hàng
                        </span>
                    </p>
                </td>
            </tr>
        </table>
	</fieldset>
    
	<p class=MsoNormal style='margin-bottom:0in;margin-bottom:.0001pt;line-height:
	normal'><span style='font-size:12.0pt;font-family:"Arial","sans-serif"'>&nbsp;</span></p>

	<p class=MsoNormal style='margin-bottom:0in;margin-bottom:.0001pt;line-height:
	normal'><span style='font-size:12.0pt;font-family:"Arial","sans-serif"'>&nbsp;</span></p>

	<fieldset>
    	<legend>THÔNG TIN GIỎ HÀNG</legend>
        <table id="cart" class=MsoTableGrid border=0 cellspacing=0 cellpadding=0 style='border-collapse:collapse;border:none'>
            <thead>
                <tr>
                    <td width=54 valign=top style='width:40.15pt;border:solid windowtext 1.0pt; padding:0in 5.4pt 0in 5.4pt'>
                        <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;text-align:center;line-height:normal'>
                            <span style='font-size:12.0pt;font-family:"Arial","sans-serif";font-weight:bold;'>STT</span>
                        </p>
                    </td>
                    <td width=111 valign=top style='width:83.0pt;border:solid windowtext 1.0pt;
                        border-left:none;padding:0in 5.4pt 0in 5.4pt'>
                        <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;
                        text-align:center;line-height:normal'><span style='font-size:12.0pt;
                        font-family:"Arial","sans-serif";font-weight:bold;'>Hình ảnh</span></p>
                    </td>
                    <td width=125 valign=top style='width:93.75pt;border:solid windowtext 1.0pt;
                        border-left:none;padding:0in 5.4pt 0in 5.4pt'>
                        <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;
                        text-align:center;line-height:normal'><span style='font-size:12.0pt;
                        font-family:"Arial","sans-serif";font-weight:bold;'>Tên sản phẩm</span></p>
                    </td>
                    <td width=103 valign=top style='width:77.55pt;border:solid windowtext 1.0pt;
                        border-left:none;padding:0in 5.4pt 0in 5.4pt'>
                        <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;
                        text-align:center;line-height:normal'><span style='font-size:12.0pt;
                        font-family:"Arial","sans-serif";font-weight:bold;'>Giá</span></p>
                    </td>
                    <td width=111 valign=top style='width:83.05pt;border:solid windowtext 1.0pt;
                        border-left:none;padding:0in 5.4pt 0in 5.4pt'>
                        <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;
                        text-align:center;line-height:normal'><span style='font-size:12.0pt;
                        font-family:"Arial","sans-serif";font-weight:bold;'>Số lượng</span></p>
                    </td>
                    <td width=111 valign=top style='width:83.05pt;border:solid windowtext 1.0pt;
                        border-left:none;padding:0in 5.4pt 0in 5.4pt'>
                        <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;
                        text-align:center;line-height:normal'><span style='font-size:12.0pt;
                        font-family:"Arial","sans-serif";font-weight:bold;'>Lựa chọn</span></p>
                    </td>
                    <td width=111 valign=top style='width:83.05pt;border:solid windowtext 1.0pt;
                        border-left:none;padding:0in 5.4pt 0in 5.4pt'>
                        <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;
                        text-align:center;line-height:normal'><span style='font-size:12.0pt;
                        font-family:"Arial","sans-serif";font-weight:bold;'>Tổng</span></p>
                    </td>
                </tr>
            </thead>
            <tbody>
                <?php
                    $receiptItems = findReceiptItemBy($receiptInfo["REC_ID"]);
                    $count = 1;
					while($row = mysql_fetch_array($receiptItems)){
                ?>
                        <tr>
                            <td width=54 valign=top style='width:40.15pt;border:solid windowtext 1.0pt;
                                border-top:none;padding:0in 5.4pt 0in 5.4pt'>
                                <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;
                                text-align:center;line-height:normal'><span style='font-size:12.0pt;
                                font-family:"Arial","sans-serif"'><?php echo $count++;?></span></p>
                            </td>
                            <td width=111 valign=top style='width:83.0pt;border-top:none;border-left:
                                none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;
                                padding:0in 5.4pt 0in 5.4pt'>
                                <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;
                                text-align:center;line-height:normal'><span style='font-size:12.0pt;
                                font-family:"Arial","sans-serif"'>
                                <?php
                                    $image = mysql_fetch_array(findLimitedImagesOfProduct($row["PRO_ID"], 1));
                                    echo "<img src='../image/product/".$row["PRO_ID"]."/".$image["IMG_PATH"]."' width='60' height='60'/>";
                                ?>
                                </span></p>
                            </td>
                            <td width=125 valign=top style='width:93.75pt;border-top:none;border-left:
                                none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;
                                padding:0in 5.4pt 0in 5.4pt'>
                                <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;
                                text-align:center;line-height:normal'><span style='font-size:12.0pt;
                                font-family:"Arial","sans-serif"'>
                                <?php
                                    $product = findProductBy($row["PRO_ID"]); 
                                    echo $product["PRO_NAME"]." (".$product["PRO_CODE"].")";
                                ?>
                                </span></p>
                            </td>
                            <td width=103 valign=top style='width:77.55pt;border-top:none;border-left:
                                none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;
                                padding:0in 5.4pt 0in 5.4pt'>
                                <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;
                                text-align:center;line-height:normal'><span style='font-size:12.0pt;
                                font-family:"Arial","sans-serif"'>
                                <?php echo number_format($row["REI_PRICE"]);?></span></p>
                            </td>
                            <td width=111 valign=top style='width:83.05pt;border-top:none;border-left:
                                none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;
                                padding:0in 5.4pt 0in 5.4pt'>
                                <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;
                                text-align:center;line-height:normal'><span style='font-size:12.0pt;
                                font-family:"Arial","sans-serif"'><?php echo $row["REI_QUANTITY"];?></span></p>
                            </td>
                            <td width=111 valign=top style='width:83.05pt;border-top:none;border-left:
                                none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;
                                padding:0in 5.4pt 0in 5.4pt'>
                                <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;
                                text-align:left;line-height:normal'><span style='font-size:12.0pt;
                                font-family:"Arial","sans-serif"'>
                                <?php
                                    $optionItems = findReceiptProductOptionItemBy($row["PRO_ID"], $row["REC_ID"]);
                                    
                                    while($optionItem = mysql_fetch_array($optionItems)){
                                        echo "- ".$optionItem["OPTIONITEM"]."<br/>";
                                    }               
                                ?>
                                </span></p>
                            </td>
                            <td width=111 valign=top style='width:83.05pt;border-top:none;border-left:
                                none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;
                                padding:0in 5.4pt 0in 5.4pt'>
                                <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;
                                text-align:center;line-height:normal'><span style='font-size:12.0pt;
                                font-family:"Arial","sans-serif"'>
                                <?php
                                    $subtotal += ($row["REI_PRICE"] * $row["REI_QUANTITY"]);
                                    echo number_format($row["REI_PRICE"] * $row["REI_QUANTITY"]);
                                ?>
                                </span></p>
                            </td>
                        </tr>
                <?php
                    }
                ?>
                <tr style='height:9.85pt;'>
                    <td width=289 colspan=5 valign=top style='width:216.9pt;border:solid windowtext 1.0pt;
                        border-top:none;padding:0in 5.4pt 0in 5.4pt;height:9.85pt'>
                        <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;
                        text-align:center;line-height:normal'><span style='font-size:12.0pt;
                        font-family:"Arial","sans-serif"'>&nbsp;</span></p>
                    </td>
                    <td width=111 valign=top style='width:83.05pt;border:none;border-bottom:solid windowtext 1.0pt;
                        padding:0in 5.4pt 0in 5.4pt;height:9.85pt'>
                        <p class=MsoNormal align=right style='margin-bottom:0in;margin-bottom:.0001pt;
                        text-align:right;line-height:normal'><span style='font-size:12.0pt;
                        font-family:"Arial","sans-serif"'>Tổng tiền:</span></p>
                    </td>
                    <td width=111 valign=top style='width:83.05pt;border-top:none;border-left:
                        none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;
                        padding:0in 5.4pt 0in 5.4pt;height:9.85pt'>
                        <p class=MsoNormal align=center style='margin-bottom:0in;margin-bottom:.0001pt;
                        text-align:center;line-height:normal'><span style='font-size:12.0pt;
                        font-family:"Arial","sans-serif"'><?php echo number_format($subtotal);?></span></p>
                    </td>
     			</tr>
            </tbody>
        </table>
	</fieldset>
    
	<p class=MsoNormal style='margin-bottom:0in;margin-bottom:.0001pt;line-height:
	normal'><span style='font-size:12.0pt;font-family:"Arial","sans-serif"'>&nbsp;</span></p>

	<p class=MsoNormal style='margin-bottom:0in;margin-bottom:.0001pt;line-height:
	normal'><span style='font-size:12.0pt;font-family:"Arial","sans-serif"'>&nbsp;</span></p>

	<p class=MsoNormal style='margin-bottom:0in;margin-bottom:.0001pt;line-height:
	normal'><span style='font-size:12.0pt;font-family:"Arial","sans-serif"'>Yêu cầu
	của hóa đơn:</span></p>

	<p class=MsoNormal style='margin-bottom:0in;margin-bottom:.0001pt;line-height:
	normal'><span style='font-size:12.0pt;font-family:"Arial","sans-serif"'>Trạng
	thái đơn hàng: <span style='color:red'>Đang chờ xử lý</span></span></p>

	<p class=MsoNormal style='margin-bottom:0in;margin-bottom:.0001pt;line-height:
	normal'><span style='font-size:12.0pt;font-family:"Arial","sans-serif"'>&nbsp;</span></p>

	<p class=MsoNormal style='margin-bottom:0in;margin-bottom:.0001pt;line-height:
	normal'><b><span style='font-size:12.0pt;font-family:"Arial","sans-serif"'>Mọi 
	chi  tiết thắc mắc hoặc yêu  cầu  tư vấn, vui  lòng gọi: 08.39 820 196 - 08.39
	820 186</span></b><span style='font-size:12.0pt;font-family:"Arial","sans-serif"'>
	Gặp bộ phận kinh  doanh.</span></p>

</div>
</body>
</html>
